import "package:flutter/material.dart";
import "package:myapp/_widget/swiper.dart";

class AnimateSwiperItem {
  String coverUrl; //图片地址
  String title; //标题
  bool isAdvertisement; //是否为广告
  AnimateSwiperItem({
    required this.coverUrl,
    required this.title,
    this.isAdvertisement = false,
  });
}

// ignore: must_be_immutable
class AnimateSwiper extends StatelessWidget {
  List<AnimateSwiperItem> animateSwiperList = [
    AnimateSwiperItem(
      coverUrl: "./images/1.jpg",
      title: '住我家算怎么回事',
    ),
    AnimateSwiperItem(
      coverUrl: "./images/3.jpg",
      title: '能够露出笑容',
    ),
    AnimateSwiperItem(
      coverUrl: "./images/1.jpg",
      title: '日志 01 前往海之摇篮',
    ),
    AnimateSwiperItem(
      coverUrl: "./images/3.jpg",
      title: '订阅送免费漫画券啦',
      isAdvertisement: true,
    ),
  ];
  AnimateSwiper({super.key});
  @override
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
      child: Padding(
        padding: const EdgeInsets.fromLTRB(6, 3, 6, 3),
        child: AspectRatio(
          aspectRatio: 16 / 9,
          child: ClipRRect(
            borderRadius: BorderRadius.circular(8),
            child: Swiper(
              height: 200,
              onCurrentIndexChange: (int index) {},
              loop: true,
              auto: false,
              showIndicator: true,
              animatedDuration: const Duration(milliseconds: 150),
              duration: const Duration(milliseconds: 2500),
              indicatorRadius: 4,
              children: animateSwiperList
                  .map(
                    (e) => Stack(
                      children: [
                        Image.asset(
                          e.coverUrl,
                          height: double.infinity,
                          width: double.infinity,
                          fit: BoxFit.cover,
                        ),
                        Positioned(
                          left: 10,
                          bottom: 8,
                          child: Text(
                            e.title,
                            style: const TextStyle(
                              color: Colors.white,
                              fontSize: 13,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      ],
                    ),
                  )
                  .toList(),
            ),
          ),
        ),
      ),
    );
  }
}
